package com.example.ignite.cotroller;

import com.example.ignite.entity.Order;
import com.example.ignite.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
@RequestMapping("/item")
@Slf4j
public class ItemDbController {

    @Autowired
    OrderService orderService;

    @RequestMapping("/dbput")
    public Integer dbput(Integer key){
        String orderId = Integer.toString(key==null? Math.abs(new Random().nextInt()) : key);
        return orderService.insert(orderId);
    }

    @RequestMapping("/dbget")
    public Order dbget(Integer key){
        String orderId = Integer.toString(key==null? Math.abs(new Random().nextInt()) : key);
        return orderService.selectByPrimaryKey(orderId);
    }
}
